package cn.monkey.chat.server.connect.chat.filter;

import cn.monkey.chat.server.connect.chat.ChatExchange;
import cn.monkey.chat.server.proto.Package;
import cn.monkey.io.transport.core.server.DefaultFilterChain;
import cn.monkey.io.transport.core.server.Filter;
import cn.monkey.io.transport.core.server.FilterChain;
import cn.monkey.state.scheduler.SchedulerManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.ArrayList;
import java.util.List;

@Configuration
public class ChatMessageFilterConfig {

    @Bean
    ChatMessageFilter groupOrPrivateChatMessageFilter() {
        return new GroupOrPrivateChatMessageFilter();
    }

    @Bean
    ChatMessageFilter lastChatMessageFilter(SchedulerManager schedulerManager) {
        return new LastChatMessageFilter(schedulerManager);
    }

    @Bean
    FilterChain<ChatExchange, cn.monkey.chat.server.proto.Package> chatMessageFilterChain(List<ChatMessageFilter> chatMessageFilters) {
        List<Filter<ChatExchange, Package>> filters = new ArrayList<>(chatMessageFilters);
        return new DefaultFilterChain<>(filters);
    }

}
